package org.example.controller;

import org.example.bean.Product;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
public class ProductController {

    @RequestMapping(value = "/getProduct/{id}")
    public Product getProduct(@PathVariable("id") String id){
        Product product = new Product();
        product.setId(id);
        product.setName("华为手机");
        product.setNum(100);
        product.setPrice(new BigDecimal(9999));
        System.out.println("查询商品信息："+id);
        return product;
    }

    @RequestMapping(value = "/getProductList")
    public List<Product> getProductList(){
        Product product = new Product();
        product.setId("909");
        product.setName("华为手机");
        product.setNum(100);
        product.setPrice(new BigDecimal(9999));
        System.out.println("查询商品信息：");
        try{
            TimeUnit.SECONDS.sleep(12);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Arrays.asList(product);
    }

}
